package com.shujia.day17;

import java.util.function.Supplier;

public class Demo08JavaMoreLambda {
    public static void main(String[] args) {
        Student student = new Student("汪雨", 18);
        String name = student.getName();
        System.out.println(name);

        Supplier<String> sup = () -> student.getName();
        String name2 = sup.get();
        System.out.println(name2);

        Supplier<String> sup2 = student::getName;
        System.out.println(sup2.get());

        // TODO 如果想要获取Student对象的姓名
        Name name1 = new Name() {
            @Override
            public String getName() {
                return student.getName();
            }
        };
        printName(name1);

//        Name name4 = student::getName;
//        printName(name4);
        // TODO 对象的引用 :: 实例方法名
        printName(student::getName);

        // TODO 类 :: 静态方法名
        printName(Student::getInfo);

        // TODO 类 :: 非静态方法
        StuGetString stuGetString = Student :: getInfo2;
        System.out.println(stuGetString.getName(new Student(), "这是类调用非静态方法"));

        Student student1 = new Student();

        // TODO 构造方法引用 ClassName::new
        GetStu getStu = ()-> new Student();
        System.out.println(getStu.getStu());

        GetStu getStu2 = Student::new;
        System.out.println(getStu2.getStu());
        System.out.println(getStu2.getStu());

        // 数组引用
        GetArray<String> getArray = String[]::new ;
        String[] array = getArray.getArray(1);


    }

    public static void printName(Name name) {
        System.out.println(name.getName());
    }



}

interface Name {
    String getName();
}

interface StuGetString{
    String getName(Student student,String info);
}

interface GetStu{
    Student getStu();
}

interface GetArray<T>{
    T[] getArray(Integer integer);
}